package com.qidianit.mes.pro.controller;

import com.qidianit.mes.pojo.pro.Process;
import com.qidianit.mes.pro.service.ProcessService;
import com.qidianit.mes.common.Result;
import com.qidianit.mes.vo.ProcessPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Package Path: com.alhz.mespro.controller
 * Author: Alhz
 * Description:
 * Date: 2025/9/17 14:01
 */
@RestController
@RequestMapping("/process")
public class ProcessController {
    @Autowired
    private ProcessService processService;

    /**
     * 分页查询工序
     * @param processPageVo
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public Result selectAllProcess(ProcessPageVo processPageVo,
                                   @RequestParam(defaultValue = "1") int page,
                                   @RequestParam(defaultValue = "10") int pageSize) {
        return processService.getProcessList(processPageVo,page,pageSize);
    }

    /**
     * 添加新工序
     * @param process
     * @return
     */
    @PostMapping("/add")
    public Result addProcess(@RequestBody Process process) {
        System.out.println(process);
        return processService.addProcess(process);
    }

    /**
     * 根据code获取工序
     * @param code
     * @return
     */
    @GetMapping("/code/{code}")
    public Result getProcessByCode(@PathVariable("code") String code){
        return processService.getProcessByCode(code);
    }

    /**
     * 更新信息
     * @param process
     * @return
     */
    @PutMapping("/update")
    public Result updateProcess(@RequestBody Process process){
        return processService.updateProcess(process);
    }

    /**
     * 根据id删除工序
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteProcessById(@PathVariable("id") Long id){
        return processService.deleteProcessById(id);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/batchDelete")
    public Result deleteProcessByIds(@PathVariable("ids")Long[] ids){
        return processService.batchDeleteProcess(ids);
    }

}
